package cn.kgc.vue.controller;

import cn.kgc.vue.common.ResponseResult;
import cn.kgc.vue.common.ResponseStatus;
import cn.kgc.vue.entity.Student;
import cn.kgc.vue.form.StudentLsitForm;
import cn.kgc.vue.mapper.StudentMapper;
import cn.kgc.vue.service.StudentService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/***
 *@title StudentController
 *@author 韩旭
 *@version 1.0.0
 *@create 2023/8/19 11:45
 **/
@RestController
@RequestMapping("student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping("getstudentNo")
    public ResponseResult getstudentNo() {
        ResponseResult responseResult = new ResponseResult();
        List<Student> list = studentService.list();
        responseResult.success(ResponseStatus.SUCCESS,list);
        return responseResult;
    }

    //查看用户信息和模糊查询
    @GetMapping("list")
    public ResponseResult list(StudentLsitForm studentLsitForm) {
        return studentService.getlist(studentLsitForm);
    }

    //添加和修改用户信息
    @PostMapping("addorupdate")
    public ResponseResult addorupdate(@RequestBody Student student) {
        return studentService.addorupdate(student);
    }


    //批量删除和单一的删除
    @DeleteMapping("delete")
    @Transactional
    public ResponseResult delete(@RequestBody List<Integer> ids) {
        ResponseResult responseResult = new ResponseResult();
        studentService.removeBatchByIds(ids);
        responseResult.success(ResponseStatus.DELETE_SUCCESS);
        return responseResult;
    }

    //批量导入
    @PostMapping("batchAdd")
    public ResponseResult batchAdd(MultipartFile file) throws Exception {
        return studentService.batchAdd(file);
    }

    @GetMapping("excel")
    public void excel(HttpServletResponse response,StudentLsitForm studentLsitForm){
         studentService.excel(response,studentLsitForm);
    }

}
